home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / VISCAFE.BIN / DbDataSource.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-19  |  7.7 KB  |  358 lines

  1. package symantec.itools.db.awt;
  2.  
  3. import java.awt.Event;
  4. import java.awt.Image;
  5.  
  6. public class DbDataSource implements DataSource {
  7.    Matrix rowCache = new Matrix();
  8.    Grid view;
  9.    DbDataStore store;
  10.    DbDataUpdater updater;
  11.    MetaTable meta;
  12.    boolean caching = false;
  13.    Data currData;
  14.    int currDataRow;
  15.    int currDataCol;
  16.  
  17.    public DbDataSource(Grid var1, DbDataStore var2, DbDataUpdater var3, MetaTable var4) {
  18.       this.view = var1;
  19.       this.setupSource(var2, var3, var4);
  20.    }
  21.  
  22.    public Grid getView() {
  23.       return this.view;
  24.    }
  25.  
  26.    public void setupSource(DbDataStore var1, DbDataUpdater var2, MetaTable var3) {
  27.       this.store = var1;
  28.       this.store.setDbDataSource(this);
  29.       this.updater = var2;
  30.       this.meta = var3;
  31.       if (this.meta != null) {
  32.          this.meta.setDbDataSource(this);
  33.       }
  34.  
  35.       this.caching = !this.store.supportsCaching();
  36.    }
  37.  
  38.    public void setGrid(Grid var1) {
  39.       this.view = var1;
  40.    }
  41.  
  42.    public void fetchMode(boolean var1) {
  43.       this.store.fetchMode(var1);
  44.    }
  45.  
  46.    public void setDefaultData(Data var1) {
  47.    }
  48.  
  49.    public void setDefaultData() {
  50.    }
  51.  
  52.    public boolean supportsMeta() {
  53.       return this.meta != null;
  54.    }
  55.  
  56.    public Matrix getCache() {
  57.       return this.rowCache;
  58.    }
  59.  
  60.    public int lastCachedRow() {
  61.       return this.rowCache.rows() - 1;
  62.    }
  63.  
  64.    public MetaTable getMetaTable() {
  65.       return this.meta;
  66.    }
  67.  
  68.    public void setupGrid(Grid var1) throws TypeNotSupported {
  69.       if (this.meta == null) {
  70.          throw new TypeNotSupported("MetaTable not set");
  71.       } else {
  72.          this.meta.setupGrid(this.view);
  73.       }
  74.    }
  75.  
  76.    public void commitData() throws TypeNotSupported {
  77.       if (this.currData != null && this.currData.changed()) {
  78.          this.setData(this.currDataRow, this.currDataCol - 1, this.currData);
  79.          this.currData.commit();
  80.          this.currData = null;
  81.          this.currDataRow = -1;
  82.       }
  83.  
  84.    }
  85.  
  86.    public void setCurrentRow(int var1) throws TypeNotSupported {
  87.       this.store.setCurrentRow(var1);
  88.    }
  89.  
  90.    public Data readData(int var1, int var2) throws DataNotAvailable {
  91.       ++var2;
  92.       if (this.currDataRow == var1 && this.currDataCol == var2) {
  93.          return this.currData;
  94.       } else if (this.caching && this.rowCache.contains(var1, var2)) {
  95.          return (Data)this.rowCache.elementAt(var1, var2);
  96.       } else {
  97.          Data var3 = this.store.getData(var1, var2);
  98.          if (this.caching) {
  99.             this.rowCache.addElement(var1, var2, var3);
  100.             this.markClean(var1);
  101.          }
  102.  
  103.          return var3;
  104.       }
  105.    }
  106.  
  107.    public Data getData(Coordinate var1) throws DataNotAvailable {
  108.       return this.getData(var1.row, var1.col);
  109.    }
  110.  
  111.    public Data getData(int var1, int var2) throws DataNotAvailable {
  112.       ++var2;
  113.       if (this.currDataRow == var1 && this.currDataCol == var2) {
  114.          return this.currData;
  115.       } else {
  116.          this.currData = this.readData(var1, var2 - 1);
  117.          this.currDataRow = var1;
  118.          this.currDataCol = var2;
  119.          return this.currData;
  120.       }
  121.    }
  122.  
  123.    public void addResultSetRow(int var1, Data[] var2) {
  124.       for(int var3 = 1; var3 <= var2.length; ++var3) {
  125.          this.rowCache.updateElement(var1, var3, var2[var3 - 1]);
  126.       }
  127.  
  128.       this.markClean(var1);
  129.    }
  130.  
  131.    public void setData(int var1, int var2, Data var3) throws TypeNotSupported {
  132.       ++var2;
  133.       if (this.caching) {
  134.          this.rowCache.updateElement(var1, var2, var3);
  135.          this.markModified(var1);
  136.       } else {
  137.          this.store.update(var1, var2, var3);
  138.       }
  139.    }
  140.  
  141.    public void setData(Coordinate var1, Data var2) throws TypeNotSupported {
  142.       this.setData(var1.row, var1.col, var2);
  143.    }
  144.  
  145.    public String getText(Coordinate var1) throws DataNotAvailable {
  146.       return this.getData(var1).toString();
  147.    }
  148.  
  149.    public void undeleteRow(int var1) throws TypeNotSupported {
  150.       if (this.caching) {
  151.          this.markModified(var1);
  152.       }
  153.  
  154.       this.updater.undeleteRow(var1);
  155.    }
  156.  
  157.    public void deleteRow(int var1) throws TypeNotSupported {
  158.       if (this.caching) {
  159.          this.markDeleted(var1);
  160.       }
  161.  
  162.       this.updater.deleteRow(var1);
  163.    }
  164.  
  165.    public void insertRow(int var1) throws TypeNotSupported {
  166.       this.updater.insertRow(var1);
  167.    }
  168.  
  169.    public int appendRow() throws TypeNotSupported {
  170.       return this.updater.appendRow();
  171.    }
  172.  
  173.    public boolean supports(Coordinate var1, int var2) {
  174.       return var2 == 1;
  175.    }
  176.  
  177.    public Image getImage(Coordinate var1) throws DataNotAvailable {
  178.       return this.getData(var1).toImage();
  179.    }
  180.  
  181.    public boolean handleEvent(Event var1) {
  182.       switch (var1.id) {
  183.          case 54:
  184.             this.rollback();
  185.          case 1005:
  186.          default:
  187.             return false;
  188.       }
  189.    }
  190.  
  191.    public void handleException(int var1, int var2, Exception var3) {
  192.       this.view.handleException(var1, var2, var3);
  193.    }
  194.  
  195.    public int rowState(int var1) {
  196.       return this.store.rowState(var1);
  197.    }
  198.  
  199.    public void clear() {
  200.       this.rowCache.removeAllElements();
  201.       this.currData = null;
  202.       this.currDataRow = -1;
  203.       this.store.clear();
  204.    }
  205.  
  206.    public void refresh() {
  207.       this.rowCache.removeAllElements();
  208.       this.currData = null;
  209.       this.currDataRow = -1;
  210.       this.store.refresh();
  211.    }
  212.  
  213.    public void undoRow(int var1) throws TypeNotSupported {
  214.       this.store.undoRow(var1);
  215.    }
  216.  
  217.    public void save() throws TypeNotSupported {
  218.       this.updater.save();
  219.    }
  220.  
  221.    public boolean isDataEditable(int var1, int var2) {
  222.       if (this.meta != null) {
  223.          try {
  224.             return this.meta.isDataEditable(var1, var2 + 1);
  225.          } catch (DataNotAvailable var3) {
  226.             return false;
  227.          }
  228.       } else {
  229.          return true;
  230.       }
  231.    }
  232.  
  233.    protected void markModified(int var1) {
  234.       if (this.rowCache.contains(var1, 0)) {
  235.          RowState var3 = (RowState)this.rowCache.elementAt(var1, 0);
  236.          var3.markModified();
  237.       } else {
  238.          RowState var2 = new RowState();
  239.          this.rowCache.addElement(var1, 0, var2);
  240.          var2.markNew();
  241.       }
  242.    }
  243.  
  244.    protected void markNew(int var1) {
  245.       RowState var2;
  246.       if (this.rowCache.contains(var1, 0)) {
  247.          var2 = (RowState)this.rowCache.elementAt(var1, 0);
  248.       } else {
  249.          var2 = new RowState();
  250.          this.rowCache.addElement(var1, 0, var2);
  251.       }
  252.  
  253.       var2.markNew();
  254.    }
  255.  
  256.    protected void markDeleted(int var1) {
  257.       RowState var2 = (RowState)this.rowCache.elementAt(var1, 0);
  258.       var2.markDeleted();
  259.    }
  260.  
  261.    protected void markClean(int var1) {
  262.       RowState var2;
  263.       if (this.rowCache.contains(var1, 0)) {
  264.          var2 = (RowState)this.rowCache.elementAt(var1, 0);
  265.       } else {
  266.          var2 = new RowState();
  267.          this.rowCache.addElement(var1, 0, var2);
  268.       }
  269.  
  270.       var2.markClean();
  271.    }
  272.  
  273.    public int validDataRowRange(int var1, int var2) throws DataNotAvailable {
  274.       return this.store.validDataRowRange(var1, var2) - 1;
  275.    }
  276.  
  277.    public int rows() {
  278.       return this.store.rowsRetrieved();
  279.    }
  280.  
  281.    public int fetchAllRows() {
  282.       return this.store.fetchAllRows();
  283.    }
  284.  
  285.    public int type(int var1, int var2) {
  286.       return 1;
  287.    }
  288.  
  289.    public void rollback(int var1, int var2) {
  290.       this.rollback();
  291.    }
  292.  
  293.    public void rollbackCurrentData() {
  294.       this.rollback();
  295.    }
  296.  
  297.    public void rollback() {
  298.       this.currData = null;
  299.       this.currDataRow = -1;
  300.    }
  301.  
  302.    public void commit(int var1, int var2) {
  303.    }
  304.  
  305.    public boolean isMasked(int var1, int var2) {
  306.       return false;
  307.    }
  308.  
  309.    public String getMask(int var1, int var2) throws TypeNotSupported {
  310.       throw new TypeNotSupported("stubbed");
  311.    }
  312.  
  313.    public boolean supportsChoice(int var1, int var2) {
  314.       return false;
  315.    }
  316.  
  317.    public Data[] getChoices(int var1, int var2) throws TypeNotSupported {
  318.       throw new TypeNotSupported("stubbed");
  319.    }
  320.  
  321.    public void setText(int var1, int var2, String var3) {
  322.    }
  323.  
  324.    public void insertChar(int var1, int var2, int var3, char var4) {
  325.    }
  326.  
  327.    public void setText(int var1, int var2, char var3) {
  328.    }
  329.  
  330.    public void appendChar(int var1, int var2, char var3) {
  331.    }
  332.  
  333.    public void clearText(int var1, int var2) {
  334.    }
  335.  
  336.    public void deleteChar(int var1, int var2, int var3) {
  337.    }
  338.  
  339.    public String subString(int var1, int var2, int var3, int var4) {
  340.       return "stubbed";
  341.    }
  342.  
  343.    public void setImage(int var1, int var2, Image var3) {
  344.    }
  345.  
  346.    public String toString(int var1, int var2) {
  347.       return "stubbed";
  348.    }
  349.  
  350.    public Image toImage(int var1, int var2) {
  351.       return null;
  352.    }
  353.  
  354.    public Object getSynchronizationObject() {
  355.       return this.store.getSynchronizationObject();
  356.    }
  357. }
  358.